# CAN测试程序的Makefile

# 编译器设置
CC = gcc
CFLAGS = -Wall -Wextra -pedantic -std=gnu99
LDFLAGS = 

# 目标文件
TARGET = can_test

# 源文件
SRCS = can_lib.c can_test.c

# 目标文件列表
OBJS = $(SRCS:.c=.o)

# 默认目标
all: $(TARGET)

# 编译规则
$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $^

# 生成目标文件的规则
%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

# 清理规则
clean:
	rm -f $(OBJS) $(TARGET)

# 安装规则
install:
	install -m 755 $(TARGET) /usr/local/bin

# 卸载规则
uninstall:
	rm -f /usr/local/bin/$(TARGET)

# 声明伪目标
.PHONY: all clean install uninstall

# 显示帮助信息
tips:
	@echo "使用说明:"
	@echo "  make           - 编译程序"
	@echo "  make clean     - 清理编译生成的文件"
	@echo "  make install   - 安装程序到/usr/local/bin"
	@echo "  make uninstall - 卸载程序"
	@echo "  make tips      - 显示此帮助信息"
	@echo "\n编译前注意:"
	@echo "  确保系统已安装linux-can相关头文件和库"
	@echo "  Ubuntu/Debian: sudo apt-get install libsocketcan-dev"
	@echo "  Fedora/CentOS: sudo yum install kernel-devel"
	@echo "\n运行前配置:"
	@echo "  1. 配置CAN接口: sudo ip link set can0 up type can bitrate 500000"
	@echo "  2. 运行程序: ./can_test [interface] [baud_rate]"